package com.hurteng.stormplane.comm;

import android.util.Log;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PipedInputStream;

public class CommSendThread extends Thread {
    private DataOutputStream socketOutputStream;
    private PipedInputStream threadInputStream;

    public CommSendThread(DataOutputStream socketOutputStream) {
        this.socketOutputStream = socketOutputStream;
        threadInputStream = new PipedInputStream();
        this.setDaemon(true);
    }

    public PipedInputStream getThreadInputStream() {
        return threadInputStream;
    }

    @Override
    public void run() {
        super.run();

        byte[] buffer = new byte[8192];

        while (true) {
            try {
                int length = threadInputStream.read(buffer);
                socketOutputStream.write(buffer, 0, length);
            } catch (IOException e) {
                Log.d("qinjinyu", e.getMessage());
            }
        }
    }
}
